package com.sea.physical.service.impl;


import com.codecrane.core.Constants;
import com.codecrane.core.power.entity.PowerUser;
import com.codecrane.core.util.PhysicalStatusEnum;
import com.sea.physical.entity.Record;
import com.sea.physical.mapper.RecordMapper;
import com.sea.physical.service.RecordService;
import org.apache.http.client.utils.DateUtils;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class RecordServiceImpl implements RecordService {

    @Autowired
    private RecordMapper recordMapper;


    @Override
    public int save(Record record) {
        return recordMapper.insert(record);
    }

    @Override
    public List<Record> findByCreateId(Record record) {
        return recordMapper.findByCreateId(record);
    }

    @Override
    public int save(Integer recordCreateId, Integer recordStatus, String recordText, String recordOperateDate) {
        PowerUser user = (PowerUser) SecurityUtils.getSubject().getSession().getAttribute(Constants.CURRENT_USER_SESSION);
        Record record=new Record();
        record.setRecordCreateId(recordCreateId);
        record.setRecordStatus(recordStatus);
        record.setRecordOperateName(user.getUserRealname());
        record.setRecordRemark(PhysicalStatusEnum.getStatusName(recordStatus));
        if(recordStatus.equals(1)){
            record.setRecordOperateDate(DateUtils.formatDate(new Date(),"yyyy-MM-dd"));
        }else {
            record.setRecordOperateDate(recordOperateDate);
        }
        return recordMapper.insert(record);
    }

}
